package com.wuqing.mybatisredisdemo.service.impl;

import com.wuqing.mybatisredisdemo.bo.StudentDetailInfoBO;
import com.wuqing.mybatisredisdemo.entity.Student;
import com.wuqing.mybatisredisdemo.mapper.StudentMapper;
import com.wuqing.mybatisredisdemo.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 卢文昊
 * @since 2021-08-02
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Autowired
    private StudentMapper studentMapper;


    @Override
    public List<Student> queryAll() {
        return studentMapper.selectAll();
    }

    @Override
    public List<Student> queryLikeName(String name) {
        return studentMapper.selectLikeName(name);
    }

    @Override
    public String saveStuInfo(Student stu) {
        return studentMapper.insertStuInfo(stu) > 0 ? "添加成功" : "添加失败";
    }

    @Override
    public String updateStuInfo(Student student) {
        return studentMapper.updateStuById(student) > 0 ? "修改成功" : "修改失败";
    }

    @Override
    public String removeById(Integer id) {
        return studentMapper.deleteStuById(id) > 0 ? "删除成功" : "删除失败";
    }

    @Override
    public List<StudentDetailInfoBO> getStudentByIdWithClassInfo(Integer id) {
        return studentMapper.selectStudentByIdWithClassInfo(id);
    }


}
